<template>
    <div>
        <div class="move-box">
            <RiskLeftModule02
                @on-handleNode="clickNode"
                :treeData="treeData"
                :leftHeight="leftHgt"
                :default-expanded-keys="['-1']"
                v-loading="loading"
            >
                <template slot="ltitle">条目组信息</template>
            </RiskLeftModule02>
            <template v-if="cutInfo === '全部选择'">
                <RiskRightModule02>
                    <p slot="rtitle">条目组信息</p>
                    <span slot="button" class="layout01-r-slot">
                        <el-button type="primary" size="mini" v-authCode.show="B_0031" @click="openAddGroupDialog" key="table1-btn1">新增</el-button>
                        <el-button type="danger" size="mini" v-authCode.show="B_0030" @click="handleGroupRemove(-1)" key="table1-btn2"
                            >删除</el-button
                        >
                        <el-button type="primary" size="mini" v-authCode.show="B_0027" key="B_0027" @click="queryVisible = true">查询</el-button>
                    </span>
                    <slot>
                        <el-table
                            :cell-style="{ padding: '0' }"
                            :row-style="{ height: '35px' }"
                            :header-row-style="{ height: '35px', padding: '5px 0' }"
                            :data="groupData"
                            v-table-top="groupPage.currentPage"
                            @selection-change="handleSelectionChange"
                            :header-cell-style="{
                                background: '#e8f3ff',
                                borderColor: '#d7d7d7',
                                fontSize: '10px',
                                fontWeight: '500',
                                'text-align': 'center',
                            }"
                            :row-class-name="tableRowColor"
                            highlight-current-row
                            highlight-hover-row
                            border
                            size="mini"
                            style="width: 100%"
                            height="calc(100vh - 140px)"
                            @sort-change="handleSort"
                        >
                            <el-table-column type="selection" width="55" size="mini" fixed="left" :selectable="selectDisabled"> </el-table-column>
                            <el-table-column prop="groupCode" label="分组编码" min-width="100" show-overflow-tooltip> </el-table-column>
                            <el-table-column prop="groupName" label="分组名称" :formatter="fomatterParam" min-width="120" show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column
                                prop="checkModifyUserNickName"
                                :formatter="fomatterParam"
                                label="更新人"
                                min-width="120"
                                show-overflow-tooltip
                            ></el-table-column>
                            <el-table-column prop="modifyDate" label="更新时间" min-width="160" show-overflow-tooltip align="center">
                                <template slot-scope="scope">
                                    {{ (dateFormat(scope.row.modifyDate) + ' ' + timeFormat(scope.row.modifyTime)).trim() || '--' }}
                                </template>
                            </el-table-column>
                            <el-table-column
                                prop="checkUserNickName"
                                :formatter="fomatterParam"
                                label="创建人"
                                min-width="120"
                                show-overflow-tooltip
                            ></el-table-column>
                            <el-table-column prop="modifyDate" label="创建时间" min-width="160" show-overflow-tooltip align="center" sortable>
                                <template slot-scope="scope">
                                    {{ (dateFormat(scope.row.createDate) + ' ' + timeFormat(scope.row.createTime)).trim() || '--' }}
                                </template>
                            </el-table-column>
                            <!-- <el-table-column prop="createUser" label="创建者" min-width="120" show-overflow-tooltip> </el-table-column> -->
                            <el-table-column label="操作" width="150">
                                <template slot-scope="scope">
                                    <RiskIconButton
                                        type="primary"
                                        icon="el-icon-view"
                                        topTitle="查看条目组"
                                        v-authCode="B_0028"
                                        key="B_0028"
                                        @on-click="openViewGroupDialog(scope.row)"
                                    ></RiskIconButton>
                                    <RiskIconButton
                                        type="primary"
                                        icon="el-icon-edit"
                                        topTitle="编辑条目组"
                                        v-authCode="B_0029"
                                        key="B_0029"
                                        @on-click="openEditGroupDialog(scope.row)"
                                    ></RiskIconButton>
                                    <RiskIconButton
                                        type="danger"
                                        icon="el-icon-delete"
                                        topTitle="删除条目组"
                                        v-authCode="B_0030"
                                        key="B_0030"
                                        @on-click="handleGroupRemove(scope.row.groupCode)"
                                    ></RiskIconButton>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="block">
                            <risk-pagination :paging="groupPage" @page-change="currentChange"></risk-pagination>
                        </div>
                    </slot>
                </RiskRightModule02>
                <!-- 新增\编辑\查看条目组信息 -->
                <yh-dialog
                    drag
                    :title="groupDialogVO.title"
                    :visible.sync="groupDialogVO.visible"
                    width="400px"
                    :close-on-click-modal="false"
                    :close-on-press-escape="false"
                >
                    <el-form label-width="120px" size="mini" ref="groupForm">
                        <el-form-item label="分组编码">
                            <el-input style="width: 220px" placeholder="自动生成" v-model="groupForm.groupCode" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="分组名称">
                            <el-input style="width: 220px" v-model="groupForm.groupName"></el-input>
                        </el-form-item>
                        <el-form-item label="创建者">
                            <el-input style="width: 220px" v-model="groupForm.createUser" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="创建日期">
                            <el-input style="width: 220px" v-model="groupForm.modifyDateshow" disabled></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button size="mini" @click="closeGroupDialog"> 取 消 </el-button>
                        <el-button v-if="groupDialogVO.action != 0" size="mini" type="primary" @click="submitGroupForm" key=""> 确 定 </el-button>
                    </div>
                </yh-dialog>

                <!-- 删除 -->
                <div>
                    <yh-dialog
                        drag
                        title="确定删除以下条目组信息吗？"
                        :visible.sync="delVisible"
                        width="500px"
                        :close-on-click-modal="false"
                        :close-on-press-escape="false"
                    >
                        <div class="remove-text">
                            <span> {{ delGroupCodeList.join(' , ') }}</span>
                        </div>
                        <div slot="footer" class="dialog-footer">
                            <el-button size="mini" @click="delVisible = false">取 消</el-button>
                            <el-button size="mini" type="primary" @click="delGroup" v-loading="delLoading">确 定</el-button>
                        </div>
                    </yh-dialog>
                </div>

                <!-- 查询 -->
                <div>
                    <yh-dialog
                        drag
                        title="查询条目组"
                        :visible.sync="queryVisible"
                        width="500px"
                        :close-on-click-modal="false"
                        :close-on-press-escape="false"
                    >
                        <el-form label-width="120px" size="mini" ref="queryForm" :model="queryForm">
                            <el-form-item label="分组编码" prop="groupCode">
                                <el-input style="width: 220px" v-model="queryForm.groupCode"></el-input>
                            </el-form-item>
                            <el-form-item label="分组名称" prop="groupName">
                                <el-input style="width: 220px" v-model="queryForm.groupName"></el-input>
                            </el-form-item>
                            <el-form-item label="更新日期" prop="modifyDate">
                                <el-date-picker
                                    style="width: 220px"
                                    v-model="queryForm.modifyDate"
                                    type="date"
                                    value-format="yyyyMMdd"
                                    placeholder="选择日期"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button size="mini" @click="queryVisible = false">取 消</el-button>
                            <el-button size="mini" @click="resetGroupForm">重 置</el-button>
                            <el-button size="mini" type="primary" @click="searchGroup" v-loading="delLoading">确 定</el-button>
                        </div>
                    </yh-dialog>
                </div>
            </template>
            <template v-else>
                <RiskRightModule02>
                    <p slot="rtitle">条目组明细</p>
                    <span slot="button" class="layout01-r-slot">
                        <el-button type="primary" size="mini" key="B_0033" v-authCode.show="B_0033" @click="queryDetailVisible = true"
                            >查询</el-button
                        >
                        <el-button type="primary" size="mini" v-authCode.show="B_0032" @click="openEditDetailDialog" v-if="showBut">编辑</el-button>
                        <el-button type="danger" size="mini" v-authCode.show="B_0034" @click="handleDetailRemove(-1)" v-if="showBut">删除</el-button>
                    </span>
                    <slot>
                        <el-table
                            :data="groupDetailData"
                            @selection-change="handleSelectionDetailChange"
                            v-table-top="groupDetailPage.currentPage"
                            border
                            :header-cell-style="{
                                background: '#e8f3ff',
                                borderColor: '#d7d7d7',
                                fontSize: '10px',
                                fontWeight: '500',
                                'text-align': 'center',
                            }"
                            :row-class-name="tableRowColor"
                            highlight-current-row
                            highlight-hover-row
                            size="mini"
                            style="width: 100%"
                            height="calc(100vh - 140px)"
                        >
                            <el-table-column type="selection" width="55" size="mini" :selectable="selectDisabled"> </el-table-column>
                            <el-table-column prop="entryCode" label="条目编号" min-width="100" show-overflow-tooltip> </el-table-column>
                            <el-table-column prop="entryName" label="风险说明" min-width="150" show-overflow-tooltip> </el-table-column>
                            <el-table-column
                                prop="entryType"
                                label="风险类型"
                                min-width="120"
                                :formatter="(row, column) => Invest.entryType[row.entryType]"
                                show-overflow-tooltip
                            >
                            </el-table-column>
                            <el-table-column
                                prop="riskCalTypes"
                                label="作用范围"
                                min-width="100"
                                :formatter="formatRiskCalTypes"
                                show-overflow-tooltip
                            ></el-table-column>
                            <el-table-column prop="entryStatusValid" label="条目状态" width="120" :formatter="formatStatus" show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column
                                prop="controlGrade"
                                label="条目级别"
                                width="100"
                                :formatter="(row, column) => dict.ControlGrade[row.controlGrade]"
                                show-overflow-tooltip
                            >
                            </el-table-column>
                            <el-table-column label="操作" width="120">
                                <template slot-scope="scope">
                                    <RiskIconButton
                                        type="danger"
                                        icon="el-icon-delete"
                                        topTitle="删除"
                                        :disabled="computedAuth || !showBut"
                                        @on-click="handleDetailRemove(scope.row.entryCode)"
                                    ></RiskIconButton>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="block">
                            <risk-pagination :paging="groupDetailPage" @page-change="currentDetailChange"></risk-pagination>
                        </div>
                    </slot>
                </RiskRightModule02>

                <!-- 编辑 -->
                <!-- 穿梭框 -->
                <RiskTransfer
                    ref="risk-transfer"
                    v-if="transferVisible"
                    :visible.sync="transferVisible"
                    title="编辑条目组明细"
                    :rightDataSource="rightTranData"
                    @submit="updateDetail"
                />
                <!-- <div>
                    <yh-dialog
                        title="编辑条目组明细"
                        :visible.sync="transferVisible"
                        width="800px"
                        v-loading="loading"
                        class="editDialog"
                        drag
                        :close-on-click-modal="false"
                        :close-on-press-escape="false"
                    >
                        <div style="height: 420px">
                            <RiskDytrantable
                                ref="trans"
                                url="/entry/list/CodeOrName"
                                index-key="entryCode"
                                left-placeholder="编号/名称"
                                right-placeholder="编号/名称"
                                :columns="tranColumns"
                                :entryType="entryType"
                                ltLevel="null"
                                :premise="false"
                                :right-table-data="rightTranData"
                                :search-names="['entryCode', 'entryName']"
                                v-if="transferVisible"
                            ></RiskDytrantable>
                        </div>
                        <div slot="footer" class="dialog-footer">
                            <el-button size="mini" @click="transferVisible = false"> 取 消 </el-button>
                            <el-button size="mini" type="primary" @click="updateDetail">确 定 </el-button>
                        </div>
                    </yh-dialog>
                </div> -->
                <!-- 删除 -->
                <div>
                    <yh-dialog
                        drag
                        title="确定删除以下条目组明细信息吗？"
                        :visible.sync="delDetailVisible"
                        width="500px"
                        :close-on-click-modal="false"
                        :close-on-press-escape="false"
                    >
                        <div class="remove-text">
                            <span> {{ delEntryCodeList.join(' , ') }}</span>
                        </div>
                        <div slot="footer" class="dialog-footer">
                            <el-button size="mini" @click="delDetailVisible = false">取 消</el-button>
                            <el-button size="mini" type="primary" @click="delDetail">确 定</el-button>
                        </div>
                    </yh-dialog>
                </div>

                <!-- 查询条目组明细 -->
                <div>
                    <yh-dialog
                        title="查询条目组明细"
                        :visible.sync="queryDetailVisible"
                        width="500px"
                        drag
                        :close-on-click-modal="false"
                        :close-on-press-escape="false"
                    >
                        <el-form label-width="120px" size="mini" ref="queryDetailForm" :model="queryDetailForm">
                            <el-form-item label="条目编号" prop="entryCode">
                                <el-input style="width: 220px" v-model="queryDetailForm.entryCode"></el-input>
                            </el-form-item>
                            <el-form-item label="风险说明" prop="entryName">
                                <el-input style="width: 220px" v-model="queryDetailForm.entryName"></el-input>
                            </el-form-item>
                            <el-form-item label="风险类型" prop="entryType">
                                <el-select style="width: 220px" v-model="queryDetailForm.entryType" clearable>
                                    <el-option
                                        v-for="item in entryTypes"
                                        :key="item.dictKey"
                                        :label="item.dictKey + '' + item.dictKeyName"
                                        :value="item.dictKey"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button size="mini" @click="queryDetailVisible = false">取 消</el-button>
                            <el-button size="mini" @click="resetGroupDetailForm">重 置</el-button>
                            <el-button size="mini" type="primary" @click="searchGroupDetail" v-loading="delLoading">确 定</el-button>
                        </div>
                    </yh-dialog>
                </div>
            </template>
        </div>
    </div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import RiskLeftModule02 from '@/common/components/risk-left-module02.vue';
import RiskRightModule02 from '@/common/components/risk-right-module02.vue';
import RiskIconButton from '@/common/components/risk-icon-button.vue';
import RiskTrantable from '@/common/components/risk-trantable.vue';
import RiskDytrantable from '@/common/components/risk-dy-trantable.vue';
import RiskTable from '@/common/components/risk-table.vue';
import { DialogVO } from '@yhfin/biz';
import { dateFormat, getCurrentPageData, timeFormat } from '@/utils/tools';
import XEUtils from 'xe-utils';
import { getUser } from '@/utils/user-util';
import Invest from '@/common/dict/invest';
import { objToArr } from '@/utils/diction-const-util';
import Index from './dict';
import router from '@/router';
import RiskPagination from '@/common/components/risk-pagination.vue';
import RiskTransfer from '@/common/components/risk-transfer.vue';

export interface pages {
    total?: number;
    pageSize?: number;
    currentPage?: number;
}
@Component({
    name: 'ItemGroupSetting',
    components: {
        RiskLeftModule02,
        RiskRightModule02,
        RiskIconButton,
        RiskTable,
        RiskTrantable,
        RiskDytrantable,
        RiskPagination,
        RiskTransfer,
    },
})
export default class ItemGroupSetting extends Vue {
    dateFormat = dateFormat;
    timeFormat = timeFormat;
    private showBut: boolean = true;
    private leftHgt: string = '100vh';
    private cutInfo: string = '全部选择';
    private groupCode: string = '';
    private treeData: any = [
        {
            label: '全部选择',
            id: '-1',
            children: [],
        },
    ];

    loading: boolean = false;

    private groupData: any[] = [];
    private groupDetailData: any[] = [];
    private groupDataList: any[] = [];
    private groupDetailDataList: any[] = [];
    private filterGroupData: any[] = [];
    private filterGroupDetailData: any[] = [];
    private selectedGroupCodeList: string[] = [];
    private selectedEntryCodeList: string[] = [];

    private delGroupCodeList: string[] = [];
    private delEntryCodeList: string[] = [];
    private groupPage: pages = {
        total: 0,
        pageSize: 25,
        currentPage: 1,
    };

    private groupDetailPage: pages = {
        total: 0,
        pageSize: 25,
        currentPage: 1,
    };
    private itemGroupSettingListMsg = {
        url: '/entry/group/list',
        returnData: { data: [], total: 0 },
        dataKey: 'data',
        title: [
            { name: '分组编码', val: 'groupCode', width: 120 },
            { name: '分组名称', val: 'groupName' },
            { name: '更新日期', val: 'modifyDate', width: 120 },
            { name: '更新时间', val: 'modifyTime', width: 120 },
            { name: '创建者', val: 'createUser', width: 100 },
            {
                name: '操作',
                type: 'btn',
                btns: [
                    { title: '查看条目组', type: 'primary', icon: 'el-icon-view', authCode: 'B_0028' },
                    { title: '编辑条目组', type: 'primary', icon: 'el-icon-edit', authCode: 'B_0029' },
                    { title: '删除条目组', type: 'danger', icon: 'el-icon-delete', authCode: 'B_0030' },
                ],
                width: 150,
            },
        ],
        height: '450px',
        // 隐藏页码
        hidePage: false,
        checked: { on: false, option: false },
    };

    private groupDialogVO: DialogVO = new DialogVO();
    private delVisible: boolean = false;
    private delDetailVisible: boolean = false;
    private queryVisible: boolean = false;
    private queryDetailVisible: boolean = false;
    private transferVisible: boolean = false;
    private groupForm = {
        groupCode: '',
        groupName: '',
        modifyDate: XEUtils.toDateString(new Date(), 'yyyyMMdd'),
        modifyDateshow: XEUtils.toDateString(new Date(), 'yyyy-MM-dd'),
        createUser: getUser().userNickName,
        userCode: '',
    };

    private groupEditForm = {
        checkUserNickName: '',
        createUser: '',
        groupCode: '',
        groupName: '',
        modifyDate: 0,
        modifyTime: 0,
        userCode: '',
    };

    private queryForm = {
        groupCode: '',
        groupName: '',
        modifyDate: '',
    };

    private queryDetailForm = {
        entryCode: '',
        entryName: '',
        entryType: '',
    };

    // 穿梭框数据
    private tranColumns: any[] = [
        {
            label: '条目编号',
            prop: 'entryCode',
            width: 80,
        },
        {
            label: '风险说明',
            prop: 'entryName',
        },
    ];
    private leftTranData: any[] = [];
    private rightTranData: any[] = [];
    private entryCodeList: string[] = [];
    private Invest: any = new Invest();
    private dict: any = new Index();
    private entryTypes: any[] = [];

    mounted() {
        this.queryGroupList(this.groupPage);
        this.entryTypes = objToArr(this.Invest.entryType);
        this.returnData();
    }

    // 左边栏选择节点
    private clickNode(data: any): void {
        if (data.id == 'DEFAULT') {
            this.showBut = false;
        } else {
            this.showBut = true;
        }
        this.cutInfo = data.label;
        this.groupCode = data.id;
        this.queryGroupDetailList();
    }

    get computedAuth() {
        const resources = getUser().resources;
        if (!resources || !resources.length) {
            return true;
        }
        const itemValue = resources.find(item => {
            return item.resourceCode === 'B_0034';
        });
        return !itemValue;
    }

    returnData() {
        console.log(1231, this.groupForm.modifyDate);
    }

    selectDisabled(row) {
        return this.showBut;
    }

    /* *********************** 条目组相关 start ********************* */

    // 获取条目组列表
    private queryGroupList(page: pages) {
        this.loading = true;
        this.$axios
            .get('/entry/group/list')
            .then((res: any) => {
                let nodeDatas = [];
                for (let item of res) {
                    let datas = item.groupCode + '-' + item.groupName;
                    nodeDatas.push({ data: item, label: datas, id: item.groupCode });
                }
                this.treeData[0].children = nodeDatas;
                this.groupDataList = res;
                this.filterGroupData = res;
                this.currentChange(1);
                this.loading = false;
            })
            .catch(() => {
                this.loading = false;
            });
    }

    // 重置条目组查询表单
    private resetGroupForm() {
        (this.$refs.queryForm as any).resetFields();
    }

    // 条目组分页
    private currentChange(val?: number): void {
        if (val) {
            this.groupPage.currentPage = val;
        }
        this.groupPage.total = this.filterGroupData.length;
        this.groupData = getCurrentPageData(this.filterGroupData, this.groupPage.currentPage, this.groupPage.pageSize);
    }

    // 查询条目组
    private searchGroup() {
        this.filterGroupData = this.handleFilter(this.groupDataList, this.queryForm);
        this.currentChange(1);
        this.queryVisible = false;
        this.yh_message_success('查询成功');
    }

    // 条目组筛选数据
    private handleFilter(dataSource: any, param: any): any {
        if (!dataSource) {
            return dataSource;
        } else {
            return dataSource.filter(
                (item: any) =>
                    (item.groupCode || '').toUpperCase().includes(param.groupCode.toUpperCase()) &&
                    (item.groupName || '').toUpperCase().includes(param.groupName.toUpperCase()) &&
                    [item.modifyDate, 0].includes(parseInt(param.modifyDate) ? parseInt(param.modifyDate) : 0)
            );
        }
    }

    // 显示新增条目组弹框
    private openAddGroupDialog() {
        this.groupForm.createUser = getUser().userNickName;
        this.groupForm.modifyDateshow = XEUtils.toDateString(new Date(), 'yyyy-MM-dd');
        this.groupDialogVO = this.groupDialogVO.getAddDialog('新增条目组信息');
    }

    // 表格斑马线
    tableRowColor({ row, rowIndex }) {
        if (rowIndex % 2 == 0) {
            return 'statistics-warning-row';
        } else {
            return 'tow-table-row';
        }
    }

    // 显示编辑条目组弹框
    private openEditGroupDialog(val: any) {
        this.groupEditForm = JSON.parse(JSON.stringify(val));
        this.groupForm.groupCode = val.groupCode;
        this.groupForm.groupName = val.groupName;
        this.groupForm.createUser = val.checkUserNickName;
        this.groupForm.modifyDateshow = val.createDate;
        this.groupDialogVO = this.groupDialogVO.getUpdateDialog('编辑条目组信息');
    }

    // 显示查看条目组弹框
    private openViewGroupDialog(val: any) {
        this.groupForm.groupCode = val.groupCode;
        this.groupForm.groupName = val.groupName;
        this.groupForm.createUser = val.checkUserNickName;
        this.groupForm.modifyDateshow = val.createDate;
        this.groupDialogVO = this.groupDialogVO.getSeeDialog('查看条目组信息');
    }

    // 显示删除条目组弹框
    private openDelGroupDialog(val: any) {}

    // 关闭弹框
    private closeGroupDialog() {
        this.groupDialogVO.visible = false;
        this.groupForm.groupCode = '';
        this.groupForm.groupName = '';
    }

    // 新增条目组
    private insertGroup() {
        this.$axios.post('/entry/group/insert', this.groupForm).then((res: any) => {
            this.closeGroupDialog();
            this.queryGroupList(this.groupPage);
            this.yh_message_success('新增成功');
        });
    }

    // 编辑条目组
    private updateGroup() {
        this.groupEditForm.groupCode = this.groupForm.groupCode;
        this.groupEditForm.groupName = this.groupForm.groupName;
        this.$axios.post('/entry/group/update', this.groupEditForm).then((res: any) => {
            this.closeGroupDialog();
            this.queryGroupList(this.groupPage);
            this.yh_message_success('更新成功');
        });
    }

    /**
     * 获得字符串实际长度，中文2，英文1
     */
    getByteLength(str) {
        let realLength = 0;
        let len = str.length;
        let charCode = -1;
        for (let i = 0; i < len; i++) {
            charCode = str.charCodeAt(i);
            if (charCode >= 0 && charCode <= 128) realLength += 1;
            else realLength += 2;
        }
        return realLength;
    }

    // 提交表单
    private submitGroupForm() {
        if (!this.groupForm.groupName || this.groupForm.groupName.length === 0) {
            this.yh_message_success('分组名称不能空！');
            return;
        }

        if (this.getByteLength(this.groupForm.groupName) > 100) {
            this.yh_message_success('分组名称长度不能大于100个字符！');
            return;
        }
        if (this.groupDialogVO.action === 1) {
            this.insertGroup();
        } else {
            this.updateGroup();
        }
    }

    // 获取条目组表格勾选数据
    private handleSelectionChange(val: any) {
        this.selectedGroupCodeList = [];
        for (var i in val) {
            this.selectedGroupCodeList.push(val[i].groupCode);
        }
    }

    // 格式化表格数据
    fomatterParam(row, column, cellValue) {
        return cellValue || cellValue == 0 ? cellValue : '--';
    }

    // 判断删除类型
    private handleGroupRemove(val: any) {
        if (val === -1) {
            if (!this.selectedGroupCodeList || this.selectedGroupCodeList.length < 1) {
                this.yh_message_warn('未选择删除项');
                return;
            }
            this.delGroupCodeList = this.selectedGroupCodeList;
        } else {
            this.delGroupCodeList = [];
            this.delGroupCodeList.push(val);
        }
        this.delVisible = true;
    }

    // 删除条目组
    private delGroup() {
        this.$axios({
            url: '/entry/group/delete',
            method: 'POST',
            data: this.delGroupCodeList,
        }).then(res => {
            this.yh_message_success('删除成功');
            this.queryGroupList(this.groupPage);
            this.delVisible = false;
        });
    }

    /* *********************** 条目组明细相关 start ********************* */
    // 获取条目组明细列表
    private queryGroupDetailList() {
        this.$axios
            .get('/entry/group/query/detail/' + this.groupCode)
            .then((res: any) => {
                this.groupDetailDataList = res;
                this.rightTranData = res;
                this.filterGroupDetailData = res;
                this.currentDetailChange(1);
            })
            .catch(() => {});
    }

    // 条目状态列转换
    private formatStatus(row): string {
        return row.entryStatusValid ? '启用' : '禁用';
    }

    // 作用范围列转换
    private formatRiskCalTypes(row) {
        let show = [];
        for (const item of row.riskCalTypes) {
            show.push(this.dict.RiskCalType[item]);
        }
        return show.join(',');
    }

    // 重置条目组查询表单
    private resetGroupDetailForm() {
        (this.$refs.queryDetailForm as any).resetFields();
    }

    // 条目组明细分页
    private currentDetailChange(val?: number): void {
        if (val) {
            this.groupDetailPage.currentPage = val;
        }
        this.groupDetailPage.total = this.filterGroupDetailData.length;
        this.groupDetailData = getCurrentPageData(this.filterGroupDetailData, this.groupDetailPage.currentPage, this.groupDetailPage.pageSize);
    }

    // 查询条目组明细
    private searchGroupDetail() {
        this.filterGroupDetailData = this.handleFilterDetail(this.groupDetailDataList, this.queryDetailForm);
        this.currentDetailChange(1);
        this.queryDetailVisible = false;
        this.yh_message_success('查询成功');
    }

    // 条目组明细筛选数据
    private handleFilterDetail(dataSource: any, param: any): any {
        if (!dataSource) {
            return dataSource;
        } else {
            return dataSource.filter(
                (item: any) =>
                    (item.entryCode || '').toUpperCase().includes(param.entryCode.toUpperCase()) &&
                    (item.entryName || '').toUpperCase().includes(param.entryName.toUpperCase()) &&
                    (item.entryType || '').toUpperCase().includes(param.entryType.toUpperCase())
            );
        }
    }
    // 显示条目组明细编辑弹框
    private openEditDetailDialog() {
        this.queryEntryList();
        this.transferVisible = true;
    }

    // 获取条目信息
    private queryEntryList() {
        this.transferVisible = true;
        this.$axios
            .post('/entry/list/CodeOrName', {
                codeOrName: '',
                entryType: '',
                paging: {
                    currentPage: 1,
                    pageSize: 25,
                },
                filterEntryCode: this.groupDetailData.map((item: any) => item.entryCode),
            })
            .then((res: any) => {
                let a = res.list;
                for (let i = 0; i < a.length; i++) {
                    a[i].id = a[i].entryCode;
                }
                this.leftTranData = a;
            });
    }

    // 编辑条目组明细
    private updateDetail(datas) {
        this.$axios
            .post(
                '/entry/group/edit/detail/' + this.groupCode,
                datas.map(i => i.entryCode)
            )
            .then((res: any) => {
                this.queryGroupDetailList();
                this.yh_message_success('更新成功');
                this.transferVisible = false;
            });
    }

    // 获取条目组明细表格勾选数据
    private handleSelectionDetailChange(val: any) {
        this.selectedEntryCodeList = [];
        for (var i in val) {
            this.selectedEntryCodeList.push(val[i].entryCode);
        }
    }

    // 判断条目组删除类型
    private handleDetailRemove(val: any) {
        if (val === -1) {
            if (!this.selectedEntryCodeList || this.selectedEntryCodeList.length < 1) {
                this.yh_message_warn('未选择删除项');
                return;
            }
            this.delEntryCodeList = this.selectedEntryCodeList;
        } else {
            this.delEntryCodeList = [];
            this.delEntryCodeList.push(val);
        }
        this.delDetailVisible = true;
    }

    // 删除条目组明细
    private delDetail() {
        this.$axios({
            url: '/entry/group/delete/detail/multiple/' + this.groupCode,
            method: 'POST',
            data: this.delEntryCodeList,
        }).then(res => {
            this.yh_message_success('删除成功');
            this.queryGroupDetailList();
            this.delDetailVisible = false;
        });
    }

    // 格式化日期
    private formatterDate({ modifyDate }) {
        return dateFormat(modifyDate, true);
    }

    // 格式化时间
    private formatterTime({ modifyTime }) {
        return timeFormat(modifyTime, true);
    }
    handleSort(column): void {
        this.groupPage.currentPage = 1;
        if (column.prop == 'createDate') {
            if (column.order == 'ascending') {
                this.filterGroupData.sort((a, b) => a.createDate.localeCompare(b.createDate) || a.createTime.localeCompare(b.createTime));
                this.groupData = getCurrentPageData(this.filterGroupData, this.groupPage.currentPage, this.groupPage.pageSize);
            } else {
                this.filterGroupData.sort((a, b) => b.createDate.localeCompare(a.createDate) || b.createTime.localeCompare(a.createTime));
                this.groupData = getCurrentPageData(this.filterGroupData, this.groupPage.currentPage, this.groupPage.pageSize);
            }
        }
    }
}
</script>
<style lang="scss" scoped>
/deep/ .el-table .statistics-warning-row {
    background: #fff !important;
}

/deep/ .el-table .tow-table-row {
    background: #fafafa !important;
}

/deep/ .el-table__body tr.current-row > td {
    background: #f3f6fe;
}
/deep/ .el-dialog .el-dialog__body {
    max-height: 100vh;
}
/deep/ .editDialog .el-dialog .el-dialog__body {
    height: fit-content;
}
</style>
